using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace Magiq.Update {
  public abstract class BaseUpdate<T> : IUpdate<T> where T : class {
    protected BaseUpdate() {
      PropertySets = new List<IPropertySet>();
    }

    protected List<IPropertySet> PropertySets { get; private set; }

    #region IUpdate<T> Members

    public IUpdate<T> Set<R>(Expression<Func<T, R>> property, R value) {
      Set(property, x => value);
      return this;
    }

    public virtual IUpdate<T> Set<R>(Expression<Func<T, R>> property, Expression<Func<T, R>> value) {
      PropertySets.Add(new PropertySet(property, value));
      return this;
    }

    public abstract int Update();

    #endregion

    protected void AddPorpertySets(IEnumerable<IPropertySet> sets) {
      PropertySets.AddRange(sets);
    }
  }
}